﻿using ChurchDiary.BLL;
using ChurchDiary.TableEntity;
using ChurchWebsite.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;

namespace ChurchWebsite.Areas.Settings.Controllers
{
    public class NotificationController : BaseController
    {
        //
        // GET: /Settings/Notification/
        int iCount = 0;
        int uCount = 0;
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult UpdateControllers()
        {
            string s = "";
            string IResult = "";
            EntityControllerActions ControllerActions = new EntityControllerActions();
            var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t);
            foreach (Type controller in controllers)
            {
                ControllerActions.ControllerName = controller.Name;

                var actions = controller.GetMethods().Where(t => t.Name != "Dispose" && !t.IsSpecialName && t.DeclaringType.IsSubclassOf(typeof(ControllerBase)) && t.IsPublic && !t.IsStatic).ToList();
                foreach (var action in actions)
                {
                    var myAttributes = action.GetCustomAttributes(false);
                    for (int j = 0; j < myAttributes.Length; j++)
                        s += string.Format("ActionName: {0}, Attribute: {1}<br>", action.Name, myAttributes[j]);
                    ControllerActions.ActionName = action.Name;
                    IResult = new BLL_Settings().UpdateControllerAction(ControllerActions);
                    if (IResult == "ISUS")
                    {
                        iCount += 1;
                    }
                    else
                    {
                        uCount += 1;
                    }
                }
            }
            return Json(iCount, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetControllers()
        {
            return Json(new BLL_Settings().GetControllerAction(),JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetController(Guid dataId)
        {
            return Json(new BLL_Settings().GetControllerAction(dataId), JsonRequestBehavior.AllowGet);
        }
        public JsonResult UpdateController(Guid dataId)
        {
            return Json(new BLL_Settings().GetControllerAction(dataId), JsonRequestBehavior.AllowGet);
        }
        public JsonResult UpdateControllerDetails(EntityControllerActions ControllerActions)
        {
            return Json(new BLL_Settings().UpdateControllerDetails(ControllerActions), JsonRequestBehavior.AllowGet);
        }
    }
}
